# Maintainer: Biswapriyo Nath <nathbappai@gmail.com>

_realname=qjackctl
pkgbase="mingw-w64-${_realname}"
pkgname="${MINGW_PACKAGE_PREFIX}-${_realname}"
pkgver=0.9.11
pkgrel=1
pkgdesc='A Qt front-end for the JACK low-latency audio server (mingw-w64)'
arch=('any')
mingw_arch=('mingw32' 'mingw64' 'ucrt64')
url='https://qjackctl.sourceforge.io'
license=('spdx:GPL-2.0-or-later')
depends=("${MINGW_PACKAGE_PREFIX}-jack2"
         "${MINGW_PACKAGE_PREFIX}-portaudio"
         $([[ ${CARCH} != i686 ]] && echo \
           "${MINGW_PACKAGE_PREFIX}-qt6-base" \
           "${MINGW_PACKAGE_PREFIX}-qt6-svg" || echo \
           "${MINGW_PACKAGE_PREFIX}-qt5-base" \
           "${MINGW_PACKAGE_PREFIX}-qt5-svg"))
makedepends=("${MINGW_PACKAGE_PREFIX}-cc"
             "${MINGW_PACKAGE_PREFIX}-cmake"
             "${MINGW_PACKAGE_PREFIX}-ninja"
             $([[ ${CARCH} != i686 ]] && echo \
               "${MINGW_PACKAGE_PREFIX}-qt6-tools" || echo \
               "${MINGW_PACKAGE_PREFIX}-qt5-tools"))
source=("https://downloads.sourceforge.net/${_realname}/${_realname}-${pkgver}.tar.gz")
sha256sums=('9ebe21b883f0b8d00ba9d52f81efa22c198c6f53d6cc605561d2e967589190f7')

build() {
  mkdir -p "${srcdir}/build-${MSYSTEM}" && cd "${srcdir}/build-${MSYSTEM}"

  declare -a _extra_config
  if check_option "debug" "n"; then
    _extra_config+=("-DCMAKE_BUILD_TYPE=Release")
  else
    _extra_config+=("-DCMAKE_BUILD_TYPE=Debug")
  fi

  if [[ ${CARCH} != i686 ]]; then
    _extra_config+=("-DCONFIG_QT6=ON")
  else
    _extra_config+=("-DCONFIG_QT6=OFF")
  fi

  MSYS2_ARG_CONV_EXCL="-DCMAKE_INSTALL_PREFIX=" \
  ${MINGW_PREFIX}/bin/cmake.exe \
    -G "Ninja" \
    "${_extra_config[@]}" \
    -DCMAKE_INSTALL_PREFIX=${MINGW_PREFIX} \
    ../${_realname}-${pkgver}

  ${MINGW_PREFIX}/bin/cmake.exe --build ./
}

package() {
  cd "${srcdir}/build-${MSYSTEM}"
  DESTDIR="${pkgdir}" ${MINGW_PREFIX}/bin/cmake.exe --install ./

  install -vDm644 "${srcdir}/${_realname}-${pkgver}/LICENSE" "${pkgdir}${MINGW_PREFIX}/share/licenses/${_realname}/LICENSE"
}
